Electronic content can include various types of graphical elements and employ various techniques in positioning those elements during execution or other use of the electronic content. Electronic content may include attributes that define or specify element size, position, and other constraints that provide various limitations on the positions and sizes of the elements. An element's position and/or size may be defined with attributes such as left, right, top, bottom, horizontal center, vertical center, baseline position, X/Y, width, height, minimum and maximum width and height, gap or space between elements, vertical alignment, horizontal alignment, width as a percentage, height as a percentage, etc. Such attributes may provide size and/or shape specification relative to the entire electronic content display area or to a container representing that entire area, or may be defined with respect to some other reference. For example, elements may be organized in a hierarchy such that one element, i.e., a parent or container element, can contain one or more other elements, i.e., its child elements. The positions and sizes of child elements can be defined relative to the container that contains them. Changes to the position and/or size of the parent can change the positions and/or size of the child elements and vise-versa. Thus, for example, when a container is resized, the child elements may change accordingly.
Constraints are thus used to constrain an element's position or size, for example, relative to other elements or to a container that contains the element. For example, one or more constraints may define the distance between a child element and the edges of the container that contains it. As another example, one or more constraints may define specified numerical values for the width and height of the element. As another example, one or more constraints may define minimums and maximums for width and height. As another example, one or more constraints may specify an amount of padding required on an element's left, right, top, and/or bottom relative to the content sides or sides of an element containing the element. As another example, one or more constraints may require input to define the text of an element.
Some types of constraints are explicitly specified by a developer during development of the electronic content. For example, a developer may specify size constraints requiring an element to be 100 pixels wide and 10 pixels tall. Other constraints depend on runtime data and thus may be considered implicitly defined. For example, a box element's size attributes may be constrained such that the box will be sized (and possibly resized during runtime) to be just big enough to fit runtime-determined text that is displayed within it.
Conventional layout features have various disadvantages in particular with respect laying out elements that have interdependent dimensions. For example, it may be desirable to have layout functionality within a piece of electronic content control the resizing of a box element that has within it a long string of text such that if the box is made shorter its height increases to accommodate the text reflowing. To handle such reflow situations developers have written specific code to calculate and set positions and sizes. Even when addressed by custom developer code, the handling of reflow situations and other layout functionality has been hindered by inefficiencies. Conventional layout techniques have further been inefficient in performing layout functions on elements the layout of which is considered “invalid,” i.e., an element's layout is considered invalid initially and after a change that requires checking whether the element needs to be laid out again. For example, multiple layout passes have been required to validate such invalidated elements because of, among other things, elements having dimensionally interdependent constraints. In addition, conventional layout techniques have included layout functionality that has involved performing unnecessary measurement calculations and/or hinders measurement optimizations by performing measurement and layout functions in separate phases.